<@html>
<script type="text/javascript">
    dojo.require("dijit.dijit");
    dojo.require("dijit.form.Form");
    dojo.require("dijit.form.DateTextBox");
    dojo.require("dijit.form.Button");
    dojo.require("dijit.form.ValidationTextBox");
</script>
<form id="addForm" method="post" dojoType="dijit.form.Form">
			<input type="hidden" name="messages.senderCode" id="senderCode" value="${(messages.senderCode)!}"/>
			<input type="hidden" name="messages.senderName" id="senderName" value="${(messages.senderName)!}"/>
			<input type="hidden" name="messages.isDeleted" id="isDeleted" value="${(messages.isDeleted)!}"/>
<table>
				<tr>
<td>
<@s.text name="code"/>：
</td>
<td>
			<input id="code" name="messages.code" dojoType="dijit.form.ValidationTextBox" required="true" />
</td>
<td>
<@s.text name="sendTime"/>：
</td>
<td>
			<input id="sendTime" name="messages.sendTime" dojoType="dijit.form.DateTextBox" required="true" />
</td>
<td>
<@s.text name="subject"/>：
</td>
<td>
			<input id="subject" name="messages.subject" dojoType="dijit.form.ValidationTextBox" required="true" />
</td>
				</tr>
				<tr>
<td>
<@s.text name="content"/>：
</td>
<td>
			<input id="content" name="messages.content" dojoType="dijit.form.ValidationTextBox" required="true" />
</td>
<td>
<@s.text name="senderCode"/>：
</td>
<td>
			<input id="senderCode" name="messages.senderCode" dojoType="dijit.form.ValidationTextBox" />
</td>
<td>
<@s.text name="senderName"/>：
</td>
<td>
			<input id="senderName" name="messages.senderName" dojoType="dijit.form.ValidationTextBox" />
</td>
				</tr>
				<tr>
<td>
<@s.text name="isDeleted"/>：
</td>
<td>
			<input id="isDeleted" name="messages.isDeleted" dojoType="dijit.form.ValidationTextBox" />
</td>
<td>
<@s.text name="msgType"/>：
</td>
<td>
			<input id="msgType" name="messages.msgType" dojoType="dijit.form.ValidationTextBox" required="true" />
</td>
		</tr>
</table>
<link rel="stylesheet" href="${(path)!}/js/dojo/dojox/grid/resources/${(theme)!}Grid.css">
<script language="javascript" type="text/javascript">
	dojo.require("dojox.grid.DataGrid");
	dojo.require("dojox.grid._CheckBoxSelector");
	dojo.require("dojo.data.ItemFileWriteStore");
</script>
<div id="messagesItems" autoHeight="true" style="width: 100%;"
	 dojoType="dojox.grid.DataGrid" singleClickEdit="true" structure="messagesItems_structure"
	 store="messagesItems_store">
</div>
<div style="width:100%; text-align:center;">
	<input type="button" id="addMessagesItems" value="增加" class="addRow"/>
	<input type="button" id="deleteMessagesItems" value="删除" class="deleteRow"/>
</div>
<script type="text/javascript" language="javascript">
	var messagesItems_store = new dojo.data.ItemFileWriteStore({
		data:{
			identifier:"id",
			label:"name",
			items:[
			<#list messages.messagesItems![] as item >
				<#if (item_index > 0)>,</#if>
				{
					"id":"${(item.id)!}"
						,"messageId": "${(item.messageId)!}"
						,"receverCode": "${(item.receverCode)!}"
						,"receverName": "${(item.receverName)!}"
						,"isReaded": "${(item.isReaded)!}"
						,"isDeleted": "${(item.isDeleted)!}"
				}
			</#list>
			]
		}
	});
	var messagesItems_structure = [
		{ type: "dojox.grid._CheckBoxSelector"}
		,
		{cells:[
			[
				new dojox.grid.cells.RowIndex({ width:"2",name:""}),
{
							"name" : "<@s.text name="messageId"/>"
							,"field" : "messageId"
							,"width" :"20%"
							,"editable" : true
							,"headerClasses" : "gridHeader"
						}
											,{
							"name" : "<@s.text name="receverCode"/>"
							,"field" : "receverCode"
							,"width" :"20%"
							,"editable" : true
							,"headerClasses" : "gridHeader"
						}
											,{
							"name" : "<@s.text name="receverName"/>"
							,"field" : "receverName"
							,"width" :"20%"
							,"editable" : true
							,"headerClasses" : "gridHeader"
						}
											,{
							"name" : "<@s.text name="isReaded"/>"
							,"field" : "isReaded"
							,"width" :"20%"
							,"editable" : true
							,"headerClasses" : "gridHeader"
						}
											,{
							"name" : "<@s.text name="isDeleted"/>"
							,"field" : "isDeleted"
							,"width" :"20%"
							,"editable" : true
							,"headerClasses" : "gridHeader"
						}
				]
		]
		}
	];
	var messagesItems_index = 0;
	//新增行按钮
	dojo.connect(dojo.byId("addMessagesItems"), "click", function() {
		messagesItems_store.newItem({
			"id" : messagesItems_index
				,"messageId": ""
				,"receverCode": ""
				,"receverName": ""
				,"isReaded": ""
				,"isDeleted": ""
		});
		messagesItems_index++;
	})
	//删除行按钮
	dojo.connect(dojo.byId("deleteMessagesItems"), "click", function() {
		dijit.byId("messagesItems").removeSelectedRows();
	})
</script>
<@listButton/>
</form>
</@html>
<script language="javascript" type="text/javascript">
    dojo.ready(function() {
        //事件注册
        //保存
        dojo.connect(dijit.byId("btnSave"),"onClick", function() {
            //校验表单
            if (dijit.byId("addForm").validate()) {
				//增加列表参数
				var param = dojo.formToObject("addForm");
				dojo.safeMixin(param,storeItemToParam(messagesItems_store, "messages.messagesItems"));
                dojo.xhrPost({
                    url : "${(path)!}/system/messages.add.do",
                    content : param,
                    handleAs : "json",
                    load : function(json) {
                        handleJsonMessage({
                            message:json,
                            callback:function() {
                                parent.publish("messages/refresh");
                                parent.closeDialog();
                            }
                        })
                    }
                });
            }
        });
    })
</script>
